﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;
using DataAccessLayer.RolesDataSetTableAdapters;
using System.Data;
using System.Collections.Specialized;
using RBS_Tools;

namespace BusinessLayer
{
    public class Members
    {
        private static tbl_MemberRolesTableAdapter TA_MemebersRoles = new tbl_MemberRolesTableAdapter();
        private static tbl_MembersTableAdapter TA_Members = new tbl_MembersTableAdapter();
        private static RolesDataSet.tbl_MembersDataTable DT_Members;

        public static bool IsInRole(string role)
        {
            return TA_MemebersRoles.IsInRole(role) == 0 ? false : true;
        }

        public static bool ValidUser(string Username, string Password)
        {
            return TA_Members.IsMember(Username, Password) == 0 ? false : true;
        }

        public static DataTable GetAllUsers()
        {
            return TA_Members.GetMembersData();
        }

        public static void AddUser(string firstname, string middlename, string lastname, string gender, string email, string alt_email, string busphone, string mobphone, string username, string password, string passquest, string passans)
        {
            try
            {
                Guid MemberID = Guid.NewGuid();
                Guid RoleID = Guid.NewGuid();
                TA_Members.Insert(MemberID, firstname, middlename, lastname, gender, email, alt_email, busphone, mobphone, username, password, passquest, passans, false, true, DateTime.Now, DateTime.Now);
                if (Roles.Exists("USER"))
                {
                    MemberRoles.AddMemberRoles(MemberID, new String[] { "USER" });
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}
